package com.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dao.mybatis.mapper.CustomerMapper;
import com.entity.Customer;
import com.entity.Pagination;

@Repository
public class CustomerDaoImp implements CustomerDao {
	@Resource
	private CustomerMapper mapper;

	@Override
	public List<Customer> getAllCustomers(Pagination pagination,Customer Customer) {
		Map<String, Object>map = new HashMap<String, Object>();
		if(pagination!=null){
			map.put("page", pagination.getCurrentPage());
			map.put("startRow", pagination.getStartRow());
			map.put("pageSize", pagination.getEveryPage());
			
		}
		if(Customer!=null){
			map.put("chName", Customer.getChName());	
			map.put("sex", Customer.getSex());
		}
		return mapper.getAllCustomers(map);
	}

	@Override
	public Integer insertCustomer(Customer Customer) {
		return mapper.insert(Customer);
	}

	@Override
	public Integer deleteCustomer(Customer Customer) {
		if(Customer==null){return -1;}
		return mapper.deleteByPrimaryKey(Customer.getId());
	}

	@Override
	public Integer updateCustomer(Customer Customer) {
		return mapper.updateByPrimaryKey(Customer);
	}

	@Override
	public int countAll(Customer Customer) {
		return mapper.countAll(Customer);
	}

	@Override
	public Customer findById(Integer id) {
		return mapper.findById(id);
	}
}
